// 长轮询服务器
const express = require('express')
const model = require('./model')
const app = express()
app.listen(3000, '0.0.0.0')

app.use(express.static('www'))

// let skip = 0

app.get('/ajax', async (req, res) => {
  let { skip } = req.query
  let timer = setInterval(async () => {
    clearInterval(timer)
    // 当前数据
    // let count = await model.countDocuments()
    let data = await model.find().skip(+skip)
    if (data.length > 0) {
      skip = data.length
      res.send(data)
    } else {
      res.status(204).send('')
    }
  }, 5000);


})

